﻿using UnityEngine;
using System.Collections;

public class Common : MonoBehaviour {
	// 公共常量
	public const int UP = 1;
	public const int DOWN = -1;
	public const int LEFT = 2;
	public const int RIGHT = -2;


	// 设计分辨率
	static int dw = 960;
	static int dh = 640;
	public static int w_ = Common.dw;
	public static int h_ = Common.dh;

	// Use this for initialization
	void Start () {
		int w = Screen.currentResolution.width;
		int h = Screen.currentResolution.height;

		if (w > dw) {
			w_ = w * dh / h;
		} else {
			h_ = h * dw / w;
		}
		Screen.SetResolution (w_, h_, true);
	}

	// Update is called once per frame
	void Update () {
	
	}

	// 从主界面回来强制横屏分辨率
	void OnApplicationPause(bool paused)
	{
		if (!paused) {
			Screen.SetResolution(w_, h_,true);
		} 
	}

	// 去掉 name 末尾的 (Clone)
	public static string getObjName (GameObject obj) {
		string name = obj.name;
		
		if (name.EndsWith("(Clone)")) {
			name = name.Substring(0, name.Length - 7);
		}
		
		return name;
	}

	// 随机数
	public static int rand(int min, int max) {
		return Random.Range (min, max + 1);
	}
}